﻿@model blacksoft.Models.HistorialViajeDataModel
@{
    ViewBag.Title = "ConsultaReserva";
    Layout = "~/Views/Shared/_LayoutCliente.cshtml";
}

<h2>Reservas / Pasajes</h2>
<form name="reserva" id="reserva">
    <div class="block big">
        <div class="block_cont">

            <table class="data-table">
                <thead>
                    <tr>
                        <td>Origen</td>
                        <td>Destino</td>
                        <td>Fecha salida viaje</td>
                        <td>Precio</td>
                        <td>Puntos a ganar</td>
                        <td>Estado</td>
                        <td>Anular</td>
                    </tr>
                </thead>
                <tbody>
                    @foreach (var item in Model.historial)
                    {
                        <tr>
                            <td>@item.origen</td>
                            <td>@item.destino</td>
                            <td>@item.fechaViaje</td>
                            <td>@item.montoPasaje</td>
                            <td>@item.puntosAGanar</td>

                            @if (item.EstadoReserva.Trim().Equals("AC"))
                            {
                                <td>RESERVA ACTIVA</td>
                            }
                            else if (item.EstadoReserva.Trim().Equals("CA"))
                            {
                                <td>RESERVA PAGADO</td>
                            }
                            else if (item.EstadoReserva.Trim().Equals("AN"))
                            {
                                <td>RESERVA ANULADO</td>
                            }
                            else
                            {
                                <td>EL SISTEMA DESCONOCE ESTA RESERVA</td>
                            }

                            @if (item.EstadoReserva.Trim().Equals("AC"))
                            {
                                <td><a href='javascript:AnularReserva(@item.IDReserva)'>Anular Reserva</a></td>
                            }
                            else
                            {
                                <td>&nbsp;</td>
                            }


                        </tr>
                    }
                </tbody>
            </table>
        </div>
    </div>
</form>
<script type="text/javascript">
    function AnularReserva(idReserva) {
        var url = '@Url.Action("AnularReserva", "INT_Reserva")';

        $.ajax({
            type: "POST",
            url: url,
            data: "{ 'IdReserva' : '" + idReserva + "' }",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (data) {
                alert(data.message);
                $("form").submit();
            },
            error: function () { alert("Se produjo un error inesperado"); }
        });
    }
</script>